package cn.edu.ldu.communityqa.communityqa.config;

import cn.edu.ldu.communityqa.communityqa.interceptor.ApiLoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    private final ApiLoginInterceptor apiLoginInterceptor;

    @Autowired
    public WebConfig(ApiLoginInterceptor apiLoginInterceptor) {
        this.apiLoginInterceptor = apiLoginInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(apiLoginInterceptor)
                .addPathPatterns("/api/hello/**") // 只拦截 /api 下的所有请求
                .excludePathPatterns("/api/auth/**") // 排除某些公共 API
                .excludePathPatterns("/api/question"); // 排除某些公共 API
    }
}